
Instructions for replicating analyses presented in Steven Liao. 
"Chinese Foreign Real Estate Investment and Local Voting in U.S. 
Presidential Elections." International Studies Quarterly.


######################################################################
*** I. Install Dependencies *** 
######################################################################

Replication created on a iMac (3.6 Ghz 10-Core Intel Core i9 with 
64 GB 2667 MHz DDR4) running macOS Monterey (12.6.3) using 
R (version 4.1.1) via RStudio (version 2021.09.0). Please install the 
following R packages used in the analyses.

- choroplethr: version = 3.7.0

- choroplethrMaps: version = 1.0.1

- choroplethrZip: version = 1.5.0

## Hosted on gihub <https://github.com/arilamstein/choroplethrZip>
## Installation
install.packages("devtools")
library(devtools)
install_github('arilamstein/choroplethrZip@v1.5.0')

- countrycode: version = 1.3.1

- gridExtra: version = 2.3

- lfe: version = 2.8-7.1

- MASS: version = 7.3-56

- multcomp: version = 1.4-18

- pBrackets: version = 1.0.1

- RColorBrewer: version = 1.1-3

- snow: version = 0.4-4

- stargazer: version = 5.2.3

- tidyverse: version = 1.3.1

- tools: version = 4.1.1

- viridis: version = 0.6.2

- xtable: version = 1.8-4


######################################################################
*** II. Datasets ***
######################################################################

The following files are datasets used in the analyses. 
Please make sure to download all files in their original format.

- data-merge-county.RData
  A county-year level dataset used in the main analyses:
    1) DID-main.R 
    2) moderation.R
    3) Figure-5-left.R
    4) Figure-5-right.R 
    5) Tables-C1-C2-C3.R
    6) Figure-D1.R
    7) Figure-E1-left.R
    8) Figure-E1-right.R

  The dataset contains 99 variables and 12,428 observations.

- foia-county-cn-under-2012.RData
  A county level dataset of Chinese international undergraduate students 
  in 2012 used in "Figure-1.R". The dataset contains 3 variables 
  and 3,220 observations.

- nar-df.RData
  A country-year level dataset used "Figure-A1.R". The 
  dataset contains 5 variables and 55 observations.

- foia-zcta.RData
  A ZCTA-country-year level dataset containing 7 variables and 
  3,619,827 observations and used in:
    1) Figure-A2.R
    2) Figure-A5.R

- pres.RData
  A county-year level dataset used "Figure-A3.R". The 
  dataset contains 5 variables and 12,437 observations.

- foia-zcta-cn-under-2012.RData
  A ZCTA-level dataset of Chinese international undergraduate students 
  in 2012 used in the analysis "Figure-A4.R". The dataset contains 5 
  variables and 33,112 observations.

- cn-frei-dest.csv
  A state-year level dataset used in "Figure-A5.R". The 
  dataset contains 3 variables and 65 observations.

- data-merge-zcta.RData
  A ZCTA-year level dataset used in the analysis "Figure-B1.R". The 
  dataset contains 52 variables and 326,646 observations.


######################################################################
*** III. R codes ***
######################################################################

The R scripts below will reproduce all the figures and tables in the 
main text and appendix. Please set the working directory to where this 
instruction file is located by changing MAIN_DIR in each R script.


1) Figure-1.R creates:
   Figure 1

2) DID-main.R creates:
   Figure 2
   Appendix Table D.1
   Appendix Table D.2
   Appendix Table D.3

3) moderation.R creates:
   Figure 3
   Figure 4
   Appendix Figure D.2
   Appendix Table D.4
   Appendix Table D.5
   
4) Figure-5-left.R creates:
   Figure 5 (left panel)
   Appendix Table E.1 (2016 GDP Growth)

5) Figure-5-right.R creates
   Figure 5 (right panel)
   Appendix Table E.1 (2016 Employment Rate)

6) Figure-A1.R creates:
   Appendix Figure A.1

7) Figure-B1.R creates:
   Appendix Figure B.1

8) Figure-A2.R creates: 
   Appendix Figure A.2

9) Figure-A3.R creates: 
   Appendix Figure A.3

10) Figure-A4.R creates:
    Appendix Figure A.4

11) Figure-A5.R creates:
    Appendix Figure A.5

12) Tables-C1-C2-C3.R creates:
    Appendix Tables C.1, C.2, and C.3

13) Figure-D1.R creates:
    Appendix Figure D.1

14) Figure-E1-left.R creates:
    Appendix Figure E.1 (left panel)
    Table E.1 (2020 GDP Growth)

15) Figure-E1-right.R creates:
    Appendix Figure E.1 (right panel)
    Table E.1 (2020 Employment Rate)


######################################################################
*** IV. Files Uploaded for File-Level Preservation ***
######################################################################

The following files are saved outputs used/described in the R scripts 
above. The R scripts document exactly how they are produced. Please 
make sure to download all files in their original format.

- sim-seq-g-2016-gdp-growth.RData
  Saved simulation results generated and used in 
  Figure-5-left.R to save computational time.

- sim-seq-g-employ-2016.RData
  Saved simulation results generated and used in 
  Figure-5-right.R to save computational time.

- sim-seq-g-2020-gdp-growth.RData
  Saved simulation results generated and used in 
  Figure-E1-left.R to save computational time.

- sim-seq-g-employ-2020.RData
  Saved simulation results generated and used in 
  Figure-E1-right.R to save computational time.

